from urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
import requests
import json
import datetime

today = datetime.date.today()  # 今天
yesterday = today - datetime.timedelta(days=1)
Platform = "天天云1_畅听书斋"


def tiantianyun1_sum():
    try:
        requests.urllib3.disable_warnings(InsecureRequestWarning)
        r = requests.session()
        url = "http://api.gungunbook.net/Login.php"
        date = {
            "user_name": "",
            "password": ""
        }
        rr = r.post(url=url, data=date, verify=False, timeout=15)
        ht = json.loads(rr.text)
        bb = ht["msg"]
        aa = r.get(url="http://api.gungunbook.net/Consume.php?action=daily&sId={0}".format(bb), verify=False,
                   timeout=15)
        html = json.loads(aa.text)
        for y in range(len(html['content'])):
            if str(html["content"][y]["time"]) == str(yesterday):
                date_time = str(yesterday)
                Amount_share = round(float(html["content"][y]["count_consume"]) * 0.9, 2)
                return date_time, Amount_share, Platform
            else:
                if y == len(html['content']) - 1:
                    return '', 'None', Platform
                else:
                    pass
    except Exception:
        print("获取 天天云1_畅听书斋 数据失败")
        return '', 'None', Platform
    except ConnectionError:
        print("获取 天天云1_畅听书斋 数据 超时")
        return '', 'None', Platform